<%@ page language="java" contentType="text/html; charset=windows-1256" pageEncoding="windows-1256"%>

<%@page import="com.ibm.eg.cvmanager.dto.*"%>
<%@page import="com.ibm.eg.cvmanager.business.stub.*"%>
<%@page import="com.ibm.eg.cvmanager.business.interfaces.*"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256">
<title>Insert title here</title>
</head>
<body>
<%
if(request.getParameter("add") != null) {
	session.removeAttribute("interview");
}

Interview interview = (Interview) session.getAttribute("interview"); 
	
if(interview == null) {
	session.setAttribute("interview", interview = new Interview());
}

if(request.getParameter("mobile") != null){
	Applicant app = new Applicant();
	
	app.setName(request.getParameter("name"));
	app.setMobile(request.getParameter("mobile"));
	app.setEmail(request.getParameter("email"));
	app.setPhone(request.getParameter("phone"));
	app.setCv(request.getParameter("cv"));
	request.getParameter("");
	interview.setApplicant(app);
}

String id = request.getParameter("id");

if(id != null) {
	InterviewBusiness business = new InterviewBusinessImpl();
	if (session.getAttribute("itnerview") == null) {
		session.setAttribute("interview", interview = business.getInterview(Integer.parseInt(id)));
	}
}
%>


<form method="post" action="hellopage.jsp">

<table align="center">
	<tr>
		<td>
			<input type="hidden" name="id" value="<%=interview.getId()%>"/>
		</td>
	</tr>
	
	
	<tr>
	<td>
	<p>Date</p>
	</td>
	<td>
	
			Day:
				<select name="day" tabindex="<%=interview.getId() == null ? "" : interview.getInterviewdate().getDay()%>">
				<% for(int i = 1;i <= 31;i++) { %>
					<option value="<%=i%>"  <%if(interview.getId() != null && interview.getInterviewdate().getDay() == i){%>selected="selected"<%}%>><%=i %></option>
				<%} %>
				</select>
			
			Month:
		
				<select name="month">
				<% for(int i = 1;i <= 12;i++) { %>
					<option value="<%=i-1%>" <%if(interview.getId() != null && interview.getInterviewdate().getMonth() == i - 1){%>selected="selected"<%}%>><%=i %></option>
				<%} %>
				</select>
			
			Year:
			<input name="year" type="text" size="4" value="<%=interview.getId() == null ? "" : interview.getInterviewdate().getYear() + 1900%>"> </td>
	
	
	</tr>
	<tr>
	<td>
	<p>State</p>
	</td>
	<td>
	
	<SELECT NAME="interview_state">
	
	<%
	for(INTERVIEW_STATUS status : INTERVIEW_STATUS.values()) {
	%>
		<OPTION VALUE="<%=status.ordinal()%>" <%if(interview.getId() != null && interview.getStatus() == status.ordinal()){%> selected="selected"<%}%>><%=status.name()%></OPTION>
	<% 
	} 
	%>
	</SELECT>

	</td>
	</tr>
	<tr>
	<td>
	<p>Comment</p>
	</td>
	<td>
	<textarea name="comment" rows="3" cols="40">
	<%=interview.getId() == null ? "" : interview.getComment()%>
	</textarea>
	</td>
	</tr>

	<tr>
	<td>
		<input type="text" size="25" value ="<%=interview.getId() == null ? "" : interview.getApplicant().getName()%>">
	</td>
	<td>
			<%
			if(interview.getApplicant() != null) {
			%>
				<a href="addnewapplicant.jsp?id=<%=interview.getApplicant().getId()%>">Update</a>
			<%	
			}
			%>
			<a href="addnewapplicant.jsp">Add</a>
	</td>
	
	
	</tr>
	
	<%
		String names="";
	InterviewerId interId;
	int i=0;
	
		if(interview.getId() != null) {
			for(Object o: interview.getInterviewers()) {
				Interviewer interviewer = (Interviewer)o;
				names="";
				
				//if(! names.isEmpty())
				//	names += ",";
				
				 interId = interviewer.getId();
			
				names = interId.getName();
	%>
	<tr>
	
		<td>
				<input  name ="interviewername"+<%=i%> type="text" size="25" value ="<%=names%>">
		</td>
		<td>
				<a href="addinterviewer.jsp?interviewid=<%=interId.getInterviewId()%>&name=<%=interId.getName()%>">Update</a>
				
		</td>
	</tr>	
		<% 
			
			i++;
			}
		%>
		
	<tr>
		<td>
				<a href="addinterviewer.jsp">Add new interviewer</a>
		</td>
	</tr>	
		
	<%
		}
		if(interview.getId() == null){
		
	%>
	<tr>
	<td>
				<input type="text" size="25" value ="<%=names%>">
		</td>
		<td>
				<a href="addinterviewer.jsp?id=<%/*=interId*/%>">Update</a>
				<a href="addinterviewer.jsp">Add</a>
		</td>
	<%} %>
	</tr>
	<tr>
	<td>
	<input type="submit" value="<%=interview.getId() == null ? "Add" : "Update"%>">
	</td>
	</tr>
</table>

</form>

</body>
</html>